package main.java.com.manger.service.Impl;

import com.manger.constant.Constant;
import com.manger.dao.StudentMapper;
import com.manger.dto.Page;
import com.manger.entity.Student;
import com.manger.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by LCJ on 2017/6/13.
 */
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public String addStudent(Student student) {
        if(studentMapper.insert(student)>0)
            return Constant.OPERATEION_SUCCESS;
        return Constant.OPERATEION_FAILURE ;
    }

    @Override
    public String deleteStudentById(Integer id) {
        if(studentMapper.deleteById(id)>0)
            return Constant.OPERATEION_SUCCESS;
        return Constant.OPERATEION_FAILURE ;
    }

    @Override
    public String updateStudent(Student student) {
        if(studentMapper.updateByPrimaryKeySelective(student)>0)
            return Constant.OPERATEION_SUCCESS;
        return Constant.OPERATEION_FAILURE ;

    }

    @Override
    public List<Student> findAllStudents(Page pag) {
        return studentMapper.findAll(pag);
    }

    @Override
    public Student findStudent(Integer id) {
        return studentMapper.findById(id);
    }

    @Override
    public Integer findCount() {
        return studentMapper.count();
    }

    @Override
    public List<Student> findStudentByKey(Long no) {
        return null;
    }

    @Override
    public Student findStudentByNo(Long no) {
        return studentMapper.findStudentByNo(no);
    }

    @Override
    public List<Student> findAllStudents() {
        return studentMapper.findAllStudents();
    }
}
